using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Text;

namespace Data_Access_Tier
{
	public class HRM_PROCESS_POSITIONData : DatabaseObjectBase
	{
		public HRM_PROCESS_POSITIONData()
		{
			Initialize(true);
		}
		public HRM_PROCESS_POSITIONData(Boolean newConnection)
		{
			Initialize(newConnection);
		}

		public Int32 HRM_PROCESS_POSITION_Insert(Guid PositionID, String EmployeeCode, String OldBranch, String OldDepartment, String OldGroup, String OldPosition, String NewBranch, String NewDepartment, String NewGroup, String NewPosition, DateTime Date, String Reason, String DecideNumber, String Person)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.InsertCommand = new SqlCommand("HRM_PROCESS_POSITION_Insert");
				_dbadapter.InsertCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.InsertCommand.Connection = _dbconn;
				_trans = _dbconn.BeginTransaction();
				_dbadapter.InsertCommand.Transaction = _trans;
				_dbadapter.InsertCommand.Parameters.Clear();
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@PositionID", SqlDbType.UniqueIdentifier));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@OldBranch", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@OldDepartment", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@OldGroup", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@OldPosition", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@NewBranch", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@NewDepartment", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@NewGroup", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@NewPosition", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Reason", SqlDbType.NVarChar, 1000));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@DecideNumber", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Person", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Prepare();
				SqlGuid PositionIDSQL = PositionID;
				_dbadapter.InsertCommand.Parameters["@PositionID"].Value = PositionIDSQL;
				SqlString EmployeeCodeSQL = EmployeeCode;
				_dbadapter.InsertCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
				SqlString OldBranchSQL = OldBranch;
				_dbadapter.InsertCommand.Parameters["@OldBranch"].Value = OldBranchSQL;
				SqlString OldDepartmentSQL = OldDepartment;
				_dbadapter.InsertCommand.Parameters["@OldDepartment"].Value = OldDepartmentSQL;
				SqlString OldGroupSQL = OldGroup;
				_dbadapter.InsertCommand.Parameters["@OldGroup"].Value = OldGroupSQL;
				SqlString OldPositionSQL = OldPosition;
				_dbadapter.InsertCommand.Parameters["@OldPosition"].Value = OldPositionSQL;
				SqlString NewBranchSQL = NewBranch;
				_dbadapter.InsertCommand.Parameters["@NewBranch"].Value = NewBranchSQL;
				SqlString NewDepartmentSQL = NewDepartment;
				_dbadapter.InsertCommand.Parameters["@NewDepartment"].Value = NewDepartmentSQL;
				SqlString NewGroupSQL = NewGroup;
				_dbadapter.InsertCommand.Parameters["@NewGroup"].Value = NewGroupSQL;
				SqlString NewPositionSQL = NewPosition;
				_dbadapter.InsertCommand.Parameters["@NewPosition"].Value = NewPositionSQL;
				SqlDateTime DateSQL = SqlDateTime.Null;
				if (Date > DateTime.MinValue)
				{
					try
					{
						DateSQL = Date;
					}
					catch (Exception eDate)
					{
						String DateMessage = eDate.Message;
						DateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.InsertCommand.Parameters["@Date"].Value = DateSQL;
				SqlString ReasonSQL = Reason;
				_dbadapter.InsertCommand.Parameters["@Reason"].Value = ReasonSQL;
				SqlString DecideNumberSQL = DecideNumber;
				_dbadapter.InsertCommand.Parameters["@DecideNumber"].Value = DecideNumberSQL;
				SqlString PersonSQL = Person;
				_dbadapter.InsertCommand.Parameters["@Person"].Value = PersonSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.InsertCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_POSITION_Insert: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_POSITION_Insert: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.InsertCommand != null)
					_dbadapter.InsertCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_POSITION_Update(Guid PositionID, String EmployeeCode, String OldBranch, String OldDepartment, String OldGroup, String OldPosition, String NewBranch, String NewDepartment, String NewGroup, String NewPosition, DateTime Date, String Reason, String DecideNumber, String Person)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_PROCESS_POSITION_Update");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@PositionID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@OldBranch", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@OldDepartment", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@OldGroup", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@OldPosition", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@NewBranch", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@NewDepartment", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@NewGroup", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@NewPosition", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Reason", SqlDbType.NVarChar, 1000));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DecideNumber", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Person", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid PositionIDSQL = PositionID;
				_dbadapter.UpdateCommand.Parameters["@PositionID"].Value = PositionIDSQL;
				SqlString EmployeeCodeSQL = EmployeeCode;
				_dbadapter.UpdateCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
				SqlString OldBranchSQL = OldBranch;
				_dbadapter.UpdateCommand.Parameters["@OldBranch"].Value = OldBranchSQL;
				SqlString OldDepartmentSQL = OldDepartment;
				_dbadapter.UpdateCommand.Parameters["@OldDepartment"].Value = OldDepartmentSQL;
				SqlString OldGroupSQL = OldGroup;
				_dbadapter.UpdateCommand.Parameters["@OldGroup"].Value = OldGroupSQL;
				SqlString OldPositionSQL = OldPosition;
				_dbadapter.UpdateCommand.Parameters["@OldPosition"].Value = OldPositionSQL;
				SqlString NewBranchSQL = NewBranch;
				_dbadapter.UpdateCommand.Parameters["@NewBranch"].Value = NewBranchSQL;
				SqlString NewDepartmentSQL = NewDepartment;
				_dbadapter.UpdateCommand.Parameters["@NewDepartment"].Value = NewDepartmentSQL;
				SqlString NewGroupSQL = NewGroup;
				_dbadapter.UpdateCommand.Parameters["@NewGroup"].Value = NewGroupSQL;
				SqlString NewPositionSQL = NewPosition;
				_dbadapter.UpdateCommand.Parameters["@NewPosition"].Value = NewPositionSQL;
				SqlDateTime DateSQL = SqlDateTime.Null;
				if (Date > DateTime.MinValue)
				{
					try
					{
						DateSQL = Date;
					}
					catch (Exception eDate)
					{
						String DateMessage = eDate.Message;
						DateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@Date"].Value = DateSQL;
				SqlString ReasonSQL = Reason;
				_dbadapter.UpdateCommand.Parameters["@Reason"].Value = ReasonSQL;
				SqlString DecideNumberSQL = DecideNumber;
				_dbadapter.UpdateCommand.Parameters["@DecideNumber"].Value = DecideNumberSQL;
				SqlString PersonSQL = Person;
				_dbadapter.UpdateCommand.Parameters["@Person"].Value = PersonSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_POSITION_Update: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_POSITION_Update: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_POSITION_Disable(Guid PositionID, ref Boolean Enabled)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_PROCESS_POSITION_Disable");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@PositionID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@enabled", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid PositionIDSQL = PositionID;
				_dbadapter.UpdateCommand.Parameters["@PositionID"].Value = PositionIDSQL;
				_dbadapter.UpdateCommand.Parameters["@enabled"].Direction = ParameterDirection.Output;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_POSITION_Disable: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_POSITION_Disable: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_POSITION_Delete(Guid PositionID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.DeleteCommand = new SqlCommand("HRM_PROCESS_POSITION_Delete");
				_dbadapter.DeleteCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.DeleteCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.DeleteCommand.Transaction = _trans;

				_dbadapter.DeleteCommand.Parameters.Clear();
				_dbadapter.DeleteCommand.Parameters.Add(new SqlParameter("@PositionID", SqlDbType.UniqueIdentifier));
				_dbadapter.DeleteCommand.Prepare();
				SqlGuid PositionIDSQL = PositionID;
				_dbadapter.DeleteCommand.Parameters["@PositionID"].Value = PositionIDSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.DeleteCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_POSITION_Delete: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_POSITION_Delete: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.DeleteCommand != null)
					_dbadapter.DeleteCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_POSITION_Save(Guid PositionID, String EmployeeCode, String OldBranch, String OldDepartment, String OldGroup, String OldPosition, String NewBranch, String NewDepartment, String NewGroup, String NewPosition, DateTime Date, String Reason, String DecideNumber, String Person)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_PROCESS_POSITION_Save");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@PositionID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@OldBranch", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@OldDepartment", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@OldGroup", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@OldPosition", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@NewBranch", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@NewDepartment", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@NewGroup", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@NewPosition", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Reason", SqlDbType.NVarChar, 1000));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DecideNumber", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Person", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid PositionIDSQL = PositionID;
				_dbadapter.UpdateCommand.Parameters["@PositionID"].Value = PositionIDSQL;
				SqlString EmployeeCodeSQL = EmployeeCode;
				_dbadapter.UpdateCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
				SqlString OldBranchSQL = OldBranch;
				_dbadapter.UpdateCommand.Parameters["@OldBranch"].Value = OldBranchSQL;
				SqlString OldDepartmentSQL = OldDepartment;
				_dbadapter.UpdateCommand.Parameters["@OldDepartment"].Value = OldDepartmentSQL;
				SqlString OldGroupSQL = OldGroup;
				_dbadapter.UpdateCommand.Parameters["@OldGroup"].Value = OldGroupSQL;
				SqlString OldPositionSQL = OldPosition;
				_dbadapter.UpdateCommand.Parameters["@OldPosition"].Value = OldPositionSQL;
				SqlString NewBranchSQL = NewBranch;
				_dbadapter.UpdateCommand.Parameters["@NewBranch"].Value = NewBranchSQL;
				SqlString NewDepartmentSQL = NewDepartment;
				_dbadapter.UpdateCommand.Parameters["@NewDepartment"].Value = NewDepartmentSQL;
				SqlString NewGroupSQL = NewGroup;
				_dbadapter.UpdateCommand.Parameters["@NewGroup"].Value = NewGroupSQL;
				SqlString NewPositionSQL = NewPosition;
				_dbadapter.UpdateCommand.Parameters["@NewPosition"].Value = NewPositionSQL;
				SqlDateTime DateSQL = SqlDateTime.Null;
				if (Date > DateTime.MinValue)
				{
					try
					{
						DateSQL = Date;
					}
					catch (Exception eDate)
					{
						String DateMessage = eDate.Message;
						DateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@Date"].Value = DateSQL;
				SqlString ReasonSQL = Reason;
				_dbadapter.UpdateCommand.Parameters["@Reason"].Value = ReasonSQL;
				SqlString DecideNumberSQL = DecideNumber;
				_dbadapter.UpdateCommand.Parameters["@DecideNumber"].Value = DecideNumberSQL;
				SqlString PersonSQL = Person;
				_dbadapter.UpdateCommand.Parameters["@Person"].Value = PersonSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_POSITION_Save: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_POSITION_Save: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_PROCESS_POSITION_GetList()
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_PROCESS_POSITION_GetList");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Prepare();
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_PROCESS_POSITION_GetList: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_PROCESS_POSITION_Get(Guid PositionID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_PROCESS_POSITION_Get");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Parameters.Add(new SqlParameter("@PositionID", SqlDbType.UniqueIdentifier));
				_dbadapter.SelectCommand.Prepare();
				SqlGuid PositionIDSQL = PositionID;
				_dbadapter.SelectCommand.Parameters["@PositionID"].Value = PositionIDSQL;
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_PROCESS_POSITION_Get: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
	}
}
